<?php

namespace Admin\Controller;
use Think\Controller;
class AdministratorController extends Controller
{
	public function __construct() {
		parent::__construct();
		$allow_action = array( //指定不需要检查登录的方法列表
			'adminLogin','logout'
			);
			if(!session('?admin_name')&& !in_array(ACTION_NAME,$allow_action)){
				$this->error('请先登录！',U('adminLogin'));
			}
	}

	public $administratorId,$administratorName,$password,$gender,$age,$phone,$email,$address;

	/**
	 * @return   void
	 */
	public function adminLogin()
	{
		// TODO: implement
		if (IS_POST) {
			//判断验证码
			//			$this->checkVerify(I('post.captcha'));
			//判断用户名和密码
			$name = I('post.AdministratorId','','trim');
			$pwd = I('post.Password','','trim');
			$rst = D('administrator')->checkUser($name,$pwd);
			if($rst!==true){
				$this->error($rst);
			}
			//			$this->success('登录成功，请稍后',U('Index/index'));
			header('location:'.U('Index/index'));
			return;
		}
//		echo D('Administrator')->password('123');
		$this->display();
	}


	/**
	 * @return   void
	 */
	public function modifySellerInformation()
	{
		$where['AdministratorId']=$_SESSION['admin_id'];
		if(IS_POST) {
			//获取传递的值
			$Model=M('administrator');
			$save['AdministratorName']=I('post.AdministratorName','');
			if(I('post.Password')!='')$save['Password']=D('Administrator')->password(I('post.Password'));
			$save['Gender']=I('post.Gender');
			$save['Age']=I('post.Age',0);
			$save['Phone']=I('post.Phone','');
			$save['Email']=I('post.Email','');
			$save['Address']=I('POST.Address','');
			$rst= $Model->where($where)->save($save);
			//判断用户名和密码
			if($rst===false){
				$this->error($rst);
			}
			session('admin_name',$save['AdministratorName']);
			echo "<script language='javascript' type='text/javascript'>alert('修改成功')</script>";
			$url = U("Index/index");
			echo "<script language='javascript' type='text/javascript'>window.location.href='$url'</script>";
			return;
		}
		// TODO: implement
		$data=M('administrator')->where($where)->find();
		$this->assign("data",$data);
		$this->display();
	}

	/**
	 * @return   void
	 */
	public function logout()
	{
		// TODO: implement
		session('[destroy]');
		//		$this->success('退出成功',__CONTROLLER__.'/adminLogin');
		header('location:'.__CONTROLLER__.'/adminLogin');
	}

	/**
	 * @return   void
	 */
	public function setDiscount()
	{
		// TODO: implement
	}
}

?>